package com.lyj.threads;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 自定义线程池拒绝策略:
 *  当提交任务数超过最大线程数 + 等待队列数 后，任务放入MySelfRejectExecutionHandler处理（当前实际是将任务放入队列等待空闲线程来处理）
 *
 */
public class MySelfRejectExecutionHandler implements RejectedExecutionHandler {

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        try {
//            BlockingQueue<Runnable> queue = executor.getQueue();
//            queue.put(r);
            System.out.println("《《《《《《《《《《《《《指定以拒绝策略触发》》》》》》》》》》》》》》");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
